import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { createClient } from 'redis';

@Module({
  providers: [
    {
      provide: 'RedisClient',
      useFactory: async (configService: ConfigService) => {
        const client = createClient({
          socket: {
            host: configService.get('redis').host,
            port: configService.get('redis').port,
          },
          database: 0
        });
        await client.connect();
        return client;
      },
      inject: [ConfigService]
    }
  ],
  exports: ['RedisClient']
})
export class RedisModule { }